package cwinsor.com.leaf_raking;

import java.util.Arrays;
import java.util.List;

public final class Team {

	private Team(String n) { name = n; } // private constructor

	private String name;

//	public static final int NUM_TEAMS = 9;

	public static final Team TEAM_1 = new Team("TEAM_1");
	public static final Team TEAM_2 = new Team("TEAM_2");
	public static final Team TEAM_3 = new Team("TEAM_3");
	public static final Team TEAM_4 = new Team("TEAM_4");
	public static final Team TEAM_5 = new Team("TEAM_5");
	public static final Team TEAM_6 = new Team("TEAM_6");
	public static final Team TEAM_7 = new Team("TEAM_7");
	public static final Team TEAM_8 = new Team("TEAM_8");
	public static final Team TEAM_UNASSIGNED = new Team("TEAM_UNASSIGNED");

	public static final List<Team> TEAMS_PLUS_UNASSIGNED = Arrays.asList(
			TEAM_1,
			TEAM_2,
			TEAM_3,
			TEAM_4,
			TEAM_5,
			TEAM_6,
			TEAM_7,
			TEAM_8,
			TEAM_UNASSIGNED);

	public static final List<Team> TEAMS_NO_U = Arrays.asList(
			TEAM_1,
			TEAM_2,
			TEAM_3,
			TEAM_4,
			TEAM_5,
			TEAM_6,
			TEAM_7,
			TEAM_8);

	/*
	 * debug
	 */
	private static String dM = "Team----";
	private static String dF = "Team---- ERROR ---- ";

	/*
	 * name
	 */
	public final String name() { return name; };

	/*
	 * stringToTeam
	 * converts string to team number
	 */
	public static final Team stringToTeam(String theString) {

		if (theString.equals("")) { return TEAM_UNASSIGNED; }
		if (Integer.valueOf(theString).equals(1)) { return TEAM_1; }
		if (Integer.valueOf(theString).equals(2)) { return TEAM_2; }
		if (Integer.valueOf(theString).equals(3)) { return TEAM_3; }
		if (Integer.valueOf(theString).equals(4)) { return TEAM_4; }
		if (Integer.valueOf(theString).equals(5)) { return TEAM_5; }
		if (Integer.valueOf(theString).equals(6)) { return TEAM_6; }
		if (Integer.valueOf(theString).equals(7)) { return TEAM_7; }
		if (Integer.valueOf(theString).equals(8)) { return TEAM_8; }

		// default
		System.out.println(dF + "in stringToTeam - cannot convert "
				+ theString 
				+ " to a Team");
		System.exit(1);
		return null;
	}


	/*
	 * stringContainsTeam
	 * converts string to team number
	 */


	public static Team stringContainsTeam(String theString) {
		return stringContainsTeam(theString, true);
	}

	public static final Team stringContainsTeam(String theString, boolean failIfNotFound) {

		if (theString.contains(Team.TEAM_1.name())) { return TEAM_1; }
		if (theString.contains(Team.TEAM_2.name())) { return TEAM_2; }
		if (theString.contains(Team.TEAM_3.name())) { return TEAM_3; }
		if (theString.contains(Team.TEAM_4.name())) { return TEAM_4; }
		if (theString.contains(Team.TEAM_5.name())) { return TEAM_5; }
		if (theString.contains(Team.TEAM_6.name())) { return TEAM_6; }
		if (theString.contains(Team.TEAM_7.name())) { return TEAM_7; }
		if (theString.contains(Team.TEAM_8.name())) { return TEAM_8; }

		// default
		if (failIfNotFound) {
			System.out.println(dF + "in stringContainsTeam - cannot convert "
					+ theString 
					+ " to a Team");
			System.exit(1);
		}
		return TEAM_UNASSIGNED;
	}


}
